package org.resty.mboot.app.exception;

import java.util.HashMap;

/**
 * Created by ZhanYuan CH on 2016/10/23.
 */
public class SystemException extends RuntimeException {
    /**
     * 直接返回内容
     */
    public static final int NONE = 0;
    /**
     * request.getRequestDispatcher( "*.jsp" ).forward( arg0, arg1 )
     */
    public static final int FORWARD = 1;
    /**
     * 类似response.sendRedirect( "*.jsp" )
     */
    public static final int REDIRECT = 2;
    /**

     *

     */
    private static final long serialVersionUID = 3546977931922180877L;
    private String responseBody;

    private String encode = "utf-8";

    private int forwardType = FORWARD;

    private HashMap<String, ?> attributes;

    private String modelPath;


    /**
     * @param responseBody
     * @param encode
     */
    public SystemException(String responseBody, String encode) {
        super();
        this.responseBody = responseBody;
        this.encode = encode;
        this.forwardType = NONE;
    }

    /**
     * @param modelPath
     * @param attributes
     */
    public SystemException(String modelPath, HashMap<String, ?> attributes) {
        super();
        this.modelPath = modelPath;
        this.attributes = attributes;
        this.forwardType = FORWARD;
    }

    /**
     * @param responseBody
     * @param encode
     * @param cause
     */
    public SystemException(String responseBody, String encode, Throwable cause) {
        super(cause);
        this.responseBody = responseBody;
        this.encode = encode;
        this.forwardType = NONE;
    }


    /**
     * @param modelPath
     * @param attributes
     * @param cause
     */
    public SystemException(String modelPath, HashMap<String, ?> attributes, Throwable cause) {
        super(cause);
        this.modelPath = modelPath;
        this.attributes = attributes;
        this.forwardType = FORWARD;
    }

    /**
     * 返回页面
     *
     * @param modelPath
     * @param forwardType SystemException.FORWARD 类似request.getRequestDispatcher( "*.jsp" ).forward( arg0, arg1 )
     *                    SystemException.REDIRECT 类似response.sendRedirect( "*.jsp" );
     */
    public SystemException(String modelPath, int forwardType) {

        super();
        this.modelPath = modelPath;
        this.forwardType = forwardType;
    }

    /**
     * 返回页面
     *
     * @param modelPath
     * @param forwardType SystemException.FORWARD 类似request.getRequestDispatcher( "*.jsp" ).forward( arg0, arg1 )
     *                    <p>
     *                    SystemException.REDIRECT 类似response.sendRedirect( "*.jsp" );
     */
    public SystemException(String modelPath, int forwardType, Throwable cause) {

        super(cause);
        this.modelPath = modelPath;
        this.forwardType = forwardType;
    }


    String getResponseBody() {
        return responseBody;
    }

    HashMap<String, ?> getAttributes() {
        return attributes;
    }

    String getModelPath() {
        return modelPath;
    }

    public String getEncode() {
        return encode;
    }

    int getForwardType() {
        return forwardType;
    }


}
